﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CTPAdapter;
using System.Threading;

namespace CTPDemo.Md
{
    class Md
    {

        CSMdApi _MdApi;

        /// <summary>
        /// 行情API接口
        /// </summary>
        public CSMdApi MdApi
        {
          get { return _MdApi; }
          set { _MdApi = value; }
        }

        CSMdSpiInter _CSMdSpi;

        /// <summary>
        /// 回调函数Spi对象
        /// </summary>
        public CSMdSpiInter CSMdSpi
        {
            get { return _CSMdSpi; }
            set { _CSMdSpi = value; }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="investorID"></param>
        /// <param name="password"></param>
        public Md(string investorID, string password, string[] ppInstrumentID)
        {
            _MdApi = new CSMdApi();
            _CSMdSpi = new MdSpi(investorID, password, _MdApi, ppInstrumentID,1);
            _MdApi.RegisterSpi(_CSMdSpi);
            _MdApi.RegisterFront("tcp://asp-sim2-md1.financial-trading-platform.com:26213");
            _MdApi.Init();

        }

        public void Release()
        {

            ((MdSpi)_CSMdSpi).UnSubscribeMarketData();

            Thread.Sleep(5000);
            ((MdSpi)_CSMdSpi).Release();
        }
    }
}
